package com.jdy.haoduoaiteacher.activity;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jdy.haoduoaiteacher.util.LeConfig;
import com.jdy.haoduoaiteacher.util.Tools;
import com.nineoldandroids.view.ViewHelper;
import com.ycsj.goldmedalnewconcept.R;

import org.droidparts.annotation.inject.InjectView;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

//import com.jdy.haoduoaiteacher.R;

/**
 * About page.
 * 
 * @author zp @ 2015-6-15 下午6:24:07
 */
public class SettingAboutActivity extends BaseActivity {

  @InjectView(id = R.id.versionTextView)
  private TextView versionTextView;

  @InjectView(id = R.id.copyrightDemonstractionTextView)
  private TextView copyrightTextView;

  @InjectView(id = R.id.setting_about_relativelayout)
  private RelativeLayout mRootLayout;
  @InjectView(id = R.id.img_abouticon, click = true)
  private ImageView img_abouticon;

  private int mTotalClicks = 0;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.setting_about_layout);
    setTitle("关于");

    ViewHelper.setTranslationY(img_abouticon, Tools.getPixelByDip(this, -40));

    mRootLayout.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        mTotalClicks++;
        if (mTotalClicks == 4) {
          mTotalClicks = 0;
          LeConfig.DEBUG_MODE = !LeConfig.DEBUG_MODE;
          LeConfig.BOOK_STORY_SWITCH = !LeConfig.BOOK_STORY_SWITCH;
          String promote = "";
          if (LeConfig.DEBUG_MODE) {
            promote = "打开";
          } else {
            promote = "关闭";
          }

          toastShow("您已" + promote + "调试模式!");
        }
      }
    });
    PackageInfo pInfo;
    try {
      pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
      if (LeConfig.DEBUG_MODE) {
        String buildTimeStamp = "";
        ApplicationInfo ai = getPackageManager().getApplicationInfo(
            getPackageName(), 0);
        ZipFile zf;
        try {
          zf = new ZipFile(ai.sourceDir);
          ZipEntry ze = zf.getEntry("classes.dex");
          long time = ze.getTime();
          buildTimeStamp = SimpleDateFormat.getInstance().format(
              new java.util.Date(time));
          zf.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        versionTextView.setText("v" + pInfo.versionName + buildTimeStamp);
      } else {
        versionTextView.setText("v" + pInfo.versionName);
      }
    } catch (NameNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

}
